﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Licenta_Stomatologie.Panels
{
    public partial class CompanyEditPanel : UserControl
    {
        Helpers.CompanyHelper cHepler = new Helpers.CompanyHelper();

        public CompanyEditPanel()
        {
            InitializeComponent();
            fillWithEditData();
        }

        private void btnSaveChanges_Click(object sender, EventArgs e)
        {
            // verificare pe judet
            if (((string)cboxJudet.SelectedItem).Length == 0)
            {
                MessageBox.Show(Helpers.ErrorMessages.ERR_CHOOSE_COUNTY);
                return;
            }

            foreach (TextBox tb in this.Controls.OfType<TextBox>())
            {
                if (tb.Text.Length == 0)
                {
                    MessageBox.Show(Helpers.ErrorMessages.ERR_EMPTY_FIELD);
                    return;
                }
            }

            String[] companyArgs = new String[] { tboxUnitateSanitara.Text, (string)cboxJudet.SelectedItem, tboxLocalitate.Text, tboxAdresa.Text, tboxNumarTelefon.Text, tboxAdresaWeb.Text };

            cHepler.createCompany(companyArgs);

            MessageBox.Show(Helpers.UserMessages.SUCCESS_EDIT_COMPANY);

            this.Controls.Clear();
            this.Controls.Add(new Panels.Dashboard());
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(Helpers.UserMessages.COMPANY_EDIT_CANCEL, "Confirmation", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                this.Controls.Clear();
                this.Controls.Add(new Panels.Dashboard());
            }
        }

        private void fillWithEditData()
        {
            String[] editData = cHepler.sendEditData();

            if (editData != null)
            {
                tboxUnitateSanitara.Text = editData[0];
                cboxJudet.SelectedItem = editData[1];
                tboxLocalitate.Text = editData[2];
                tboxAdresa.Text = editData[3];
                tboxNumarTelefon.Text = editData[4];
                tboxAdresaWeb.Text = editData[5];
            }
        }

        private void tboxAdresa_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
